package yl.hs.bmipfull.controllers.construction;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.system.IActiveService;
import yl.hs.bmipfull.service.system.ISiteMessageMainService;
import yl.hs.bmipfull.service.system.ISiteMessageReceiptService;
import yl.hs.bmipfull.utils.datastate.ActiveDeviceType;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.WebResult;

import java.util.HashMap;

/**
 * 作用:   <br/>
 * 创建时间: 2022-04-22 13:57 <br/>
 *
 * @author 吴高丰
 */
@Api(value = "工地系统", tags = "工地系统——用户消息")
@RequestMapping("/construction/news")
@RestController
public class ConstructionNewsController extends ControllerBase {
    @Autowired
    ISiteMessageReceiptService service;
    @Autowired
    ISiteMessageMainService mainservice;


    @ApiOperation(value = "查询站内信息收件信息", notes = "分页查询站内信息收件信息")
    @RequestMapping(value = "/{sn}/{rowNum}/{page}", method = RequestMethod.POST)
    public WebResult queryPage(@RequestBody PageQuery query,
                               @ApiParam(value = "登陆人编号") @PathVariable String sn,
                               @ApiParam(value = "页码") @PathVariable int page,
                               @ApiParam(value = "每页条数") @PathVariable int rowNum) {
        try {
            var result = service.queryPageSite(query, rowNum, page,sn);
            return success("ok", result);
        } catch (Exception ee) {
            return error(ee);
        }
    }
    @ApiOperation(value = "更改信件状态", notes = "更改信件状态")
    @RequestMapping(path = {"/updatestate/{usersn}/{sn}","/updatestate"}, method = RequestMethod.GET)
    public WebResult updateState(@ApiParam(value = "usersn",name = "用户编号",required = false) @PathVariable(required = false) String usersn,@ApiParam(value = "sn",name = "信件编号",required = false) @PathVariable(required = false) String sn){
        try {
            var result = mainservice.updateStateSite(usersn,sn,(short) 1);
            if(result>0){
                return success("操作成功");
            }
            return fail("操作失败");
        }catch (Exception ee){
            return  error(ee);
        }

    }
    @ApiOperation(value = "查询站内信息收件信息", notes = "根据用户编号查询站内信未读信息")
    @RequestMapping(value = "/{userSn}", method = RequestMethod.GET)
    public WebResult findByUserSn(@PathVariable String userSn) {
        try{
            var result = service.findByUserSn(userSn);
            if(result!=null){
                return success("查询成功",result.size());
            }else {
                return success("查询成功",0);
            }
        }catch (Exception ee){
            return  error(ee);
        }
    }



}
